<template>
	<view class="page tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="top-bg"></view>
		<dawnBar title="科室信息"></dawnBar>
		<view class="page-container">
			<view class="" v-if="resultData.id">

				<view class="list tn-margin-bottom-sm">
					<view class="list-item">
						<view class="list-content tn-flex tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="tn-flex tn-flex-nowrap  tn-flex-col-center tn-flex-row-left">
								<view>
									<tn-avatar shape="square" :text="resultData.name" size="130rpx"></tn-avatar>
								</view>
								<view class="tn-padding-left-ss">
									<view class="" @click="callPhoneNumber(resultData.phone)">
										<text class="tn-icon-tel-circle-fill tn-margin-right-ss"></text>
										<text>{{ resultData.phone || ''}}</text>
									</view>
									<view class="" v-if="resultData.workRange">
										<text class="tn-icon-calendar-fill dawn-text-sm tn-margin-right-ss"></text>
										<tn-tag class="dawn-tag-sm">{{resultData.workRange || '' }}</tn-tag>
									</view>
									<view class="tn-margin-top-xs">
										<text class="tn-icon-map-fill dawn-text-sm tn-margin-right-ss"></text>
										<text class="dawn-text-sm">{{ resultData.address }}</text>
									</view>
								</view>
							</view>
						</view>

						<view class="dawn-line"></view>
						<view v-if="resultData.notice"
							class=" tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="justify-content-item tn-text-df">
								<text class="tn-icon-notice-fill tn-color-black tn-margin-right-ss"></text>
								<text class="tn-color-black">{{ resultData.notice  || '' }}</text>
							</view>
						</view>
					</view>
				</view>

				<view v-if="doctorList.length > 0" class="tn-bg-white dawn-radius dawn-shadow">
					<tn-scroll-list :indicator="false">
						<view class="tn-flex tn-padding-left-xs">
							<block v-for="(item,index) in doctorList" :key="index">
								<view class="tn-padding-right-xs">
									<view @click="navNoAuth('/hosp/doctor/detail?itemId='+item.id)"
										class="tn-padding-sm tn-text-ellipsis tn-text-center">
										<view class="tn-flex tn-flex-row-center">
											<image v-if="item.headImageUrl" mode="widthFix" class="doctor-image"
												:src="item.headImageUrl">
											<image v-else mode="widthFix" class="doctor-image" src="../../static/images/icon_yygh.png">
										</view>
										<view class="tn-margin-top-ss" style="height: 18px;">
											{{item.name}}
										</view>
									</view>
								</view>
							</block>
						</view>
					</tn-scroll-list>
				</view>


				<view class='tn-bg-white dawn-shadow dawn-radius tn-margin-top-sm'>
					<view class='conters'>
						<jyf-parser :html="content" ref="article" :tag-style="tagStyle" />
					</view>
				</view>
			</view>
		</view>

		<!-- loading -->
		<dawnLoading :show="loading"></dawnLoading>

		<view v-if="show">
			<dawnMsg :msg="msg"></dawnMsg>
		</view>

		<!-- 悬浮按钮-->
		<NavBtn></NavBtn>
	</view>
</template>

<script>
	import page_mixin from '@/mixins/page_mixin.js'
	import shareInfo from '@/hosp/components/shareInfo/index.vue';
	import parser from "@/hosp/components/jyf-parser/jyf-parser";
	import * as DepartmentApi from '@/api/cms/department.js';
	import * as DoctorApi from '@/api/cms/doctor.js';
	import dayjs from "@/plugin/dayjs/dayjs.min.js";
	import * as Util from '@/utils/util.js';
	import {
		mapGetters
	} from "vuex";
	const app = getApp();

	export default {
		name: 'newsDetail',
		components: {
			shareInfo,
			"jyf-parser": parser
		},
		mixins: [page_mixin],
		computed: mapGetters(['uid', 'isLogin', 'userInfo']),
		data() {
			return {
				loading: false,
				show: false,
				msg: '暂无数据',
				id: 0,
				resultData: {},
				doctorList: [],
				store_info: {},
				content: '',
				tagStyle: {
					img: 'width:100%;'
				},
				shareInfoStatus: false,
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			if (options.hasOwnProperty('itemId')) {
				this.id = options.itemId;
			} else {
				// #ifndef H5
				uni.navigateBack({
					delta: 1
				});
				// #endif
				// #ifdef H5
				history.back();
				// #endif
			}
		},
		onShow: function() {
			this.getData();
		},
		/**
		 * 用户点击右上角分享
		 */
		// #ifdef MP
		onShareAppMessage: function() {
			return {
				title: this.resultData.title,
				imageUrl: this.resultData.picUrl ? this.resultData.picUrl : "",
				desc: this.resultData.introduction,
				path: '/hosp/department/detail?itemId=' + this.id
			};
		},
		// #endif
		methods: {
			getData: function() {
				let that = this;
				this.loading = true;
				this.show = false;
				DepartmentApi.getDepartment(this.id).then(res => {
					console.table(res)
					this.loading = false;
					if (res.code === 0) {
						this.$set(this, 'resultData', res.data);
						that.getDoctor();
						this.content = res.data.content;
						// #ifdef H5
						if (this.$wechat.isWeixin()) {
							this.setShareInfo();
						}
						// #endif

					} else {
						this.show = true;
						this.msg = '暂无数据';
					}
				});
				// 增加文章浏览量
				// ArticleApi.addArticleBrowseCount(this.id)
			},
			getDoctor: function(page) {
				let that = this;
				DoctorApi.getDoctorList({
					"departmentId":that.resultData.id,
					}).then(res => {
					console.table(res);
					if (res.code === 0) {
						const l = res.data || [];
						this.$set(that, 'doctorList', l);
					}
				});
			},
			listenerActionSheet() {
				this.shareInfoStatus = true
			},
			setShareInfoStatus() {
				this.shareInfoStatus = false
			},
			setShareInfo: function() {
				let href = location.href;
				let configAppMessage = {
					title: this.resultData.title,
					desc: this.resultData.introduction,
					link: href,
					imgUrl: this.resultData.picUrl
				};
				this.$wechat.wechatEvevt([
					"updateAppMessageShareData",
					"updateTimelineShareData"
				], configAppMessage);
			},

			fen2yuan(price) {
				return Util.fen2yuan(price)
			},
			formatDate: function(date) {
				return dayjs(date).format("YYYY-MM-DD");
			},
			formatDateTime: function(date) {
				return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
			}
		}
	}
</script>

<style lang="scss" scoped>
	.newsDetail {
		padding: 30rpx 0;
	}

	.newsDetail .title {
		padding: 0 30rpx;
		font-size: 34rpx;
		color: #282828;
		font-weight: bold;
		line-height: 1.5;
	}

	.newsDetail .item {
		padding: 20rpx 30rpx;
		// font-size: 34rpx;
		color: #8A8B8C;
		// font-weight: bold;
		line-height: 1.5;
	}

	.newsDetail .conters {
		padding: 30rpx;
		font-size: 30rpx;
		color: #282828;
		line-height: 1.7;
	}

	.newsDetail .bnt {
		color: #fff;
		font-size: 30rpx;
		width: 690rpx;
		height: 90rpx;
		border-radius: 45rpx;
		margin: 48rpx auto;
		text-align: center;
		line-height: 90rpx;
	}

	::v-deep .tn-scroll-list {
		padding-bottom: 0px;
	}

	.doctor-image {
		margin-right: 0px;
		width: 120rpx;
		height: 120rpx;
		border-radius: $dawn-border-radius;
	}
</style>